package pro.softzhang.algo.lc700;

import java.util.LinkedList;
import java.util.List;

public class LC797_AllPathsFromSourceToTarget {
    public static void main(String[] args) {

    }

    static class Solution {
        public List<List<Integer>> allPathsSourceTarget(int[][] graph) {
            List<List<Integer>> result = new LinkedList<>();
            List<Integer> path = new LinkedList<>();
            allPathsSourceTarget0(0, graph, path, result);
            return result;
        }

        private void allPathsSourceTarget0(int source, int[][] graph, List<Integer> path, List<List<Integer>> result) {
            path.add(source);
            if(source == graph.length - 1) {
                result.add(new LinkedList<>(path));
            } else {
                for (int next : graph[source]) {
                    allPathsSourceTarget0(next, graph, path, result);
                }
            }
            path.remove(path.size() - 1);
        }
    }
}
